package ru.spb.osll.myfit.client.widget;

import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.isA;
import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import ru.spb.osll.myfit.common.PageElement;
import ru.spb.osll.myfit.common.Table;
import ru.spb.osll.myfit.common.TableStyle;

import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.Widget;

public class PageElementWidgetFactoryTest extends ClientTestCase {
	private PageElementWidgetFactory pageElementFactory;
	
	public void testCreatePageElement(PageElement element,
			Class<? extends Widget> expectedClass) {
		Widget widget = pageElementFactory.getPageElementWidget(element);
		assertEquals(expectedClass.getSimpleName(), widget.getClass().getSimpleName());
		assertEquals(expectedClass, widget.getClass());
	}

	@Before
	public void setUp() {
		setUpGWTStubs();
		pageElementFactory = new PageElementWidgetFactory(gwtWidgetFactory);
		expect(menuBar.addItem(isA(MenuItem.class))).andReturn(null).anyTimes();
		expect(menuBar.addItem(isA(String.class), isA(MenuBar.class)))
				.andReturn(null).anyTimes();
	}

	@Test
	public void testCreateInclude() {
		//replayAll();
		//testCreatePageElement(new Include("", new Page()), IncludeWidget.class);
		//verifyAll();
	}
	
	@Test
	public void testCreateDoFixture() {
		replayAll();
		testCreatePageElement(new Table(TableStyle.DO_FIXTURE),
				FlexTableWidget.class);
		verifyAll();
	}

	@Test
	public void testCreateColumnFixture() {
		replayAll();
		testCreatePageElement(new Table(TableStyle.COLUMN_FIXTURE),
				FixedTableWidget.class);
		verifyAll();
	}
	
	@Test
	public void testCreateTableFixture() {
		replayAll();
		testCreatePageElement(new Table(TableStyle.MYFIT_TABLE_FIXTURE),
				MyFitTableWidget.class);
		verifyAll();
	}
	
	@Test
	public void testCreateOneLineFixture() {
		replayAll();
		testCreatePageElement(new Table(TableStyle.ONE_LINE_FIXTIRE),
				OneLineTableWidget.class);
		verifyAll();
	}
	
	@Test
	public void testCreateRowFixture() {
		replayAll();
		testCreatePageElement(new Table(TableStyle.ROW_FIXTURE),
				MyFitTableWidget.class);
		verifyAll();
	}
	
	@Test
	public void testCreateSetUpFixture() {
		replayAll();
		testCreatePageElement(new Table(TableStyle.SETUP_FIXTURE),
				FixedTableWidget.class);
		verifyAll();
	}

	@Test
	public void testCreateUnknownFixture() {
		replayAll();
		testCreatePageElement(new Table(TableStyle.UNKNOWN_FIXTURE),
				MyFitTableWidget.class);
		verifyAll();
	}

}
